Repository navigation
Conversation
… local noinline forwarder) From sourcehold#396. The gatehouse arm calls getTotalHeightAtTile through a __declspec(noinline) forwarder local to the .cpp, so the compiler does not merge it with the tower arm's identical call. reccmp reports only the forwarder's name at that call (100% normalized). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp
… a volatile cast) From sourcehold#396. The five PillarGFXLayer stores read GMFirstPictureIndex::instance[9] through a local GM_FIRST_PICTURE_INDEX #define that casts to int volatile, which keeps the compiler from merging them. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp
…atch-tricks Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp
|
Match regression check 1 of the 2 status entries behind the files this PR changes are below the best match already known on
Percentages are read from the |
…atch-tricks Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp
|
The gotos jump to two shared blocks at the end of the last
Forms tried (raw / normalized):
Flag forms, tried systematically. 78 variants generated from the goto form and compiled one by one. Each listing was compared against the 100% goto form's own listing, which is more precise than quick_diff's ratio for this function, since quick_diff misreads the original's length here. The space covered:
Findings:
So no flag form can reach 100%, and the gotos stay. Casts kept for the match (cast pass: each cast removed one at a time and the listing compared; none was redundant):
|
…atch-tricks Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp
| switch (cornerMain) { | ||
| case 1: | ||
| firstTile3 = this->DAT_SomeTile | ||
| + this->directionTranslationMatrix[0][this->DAT_SomeY * 8 + 2]; |
There was a problem hiding this comment.
Does this indicate another array dimension, or would this not make sense with the other uses?
There was a problem hiding this comment.
Yes: directionTranslationMatrix is already int [400][8]. But [this->DAT_SomeY][CD_EAST] everywhere drops updateGfxLayer from 100.0/95.2 to 93.4/49.0, so the flat [0][DAT_SomeY * CD_UPPER_LIMIT + CD_EAST] stays. The 8 and the offsets now have names (6f13203).
| } | ||
| } | ||
| if (cornerMain != 0) { | ||
| switch (cornerMain) { |
There was a problem hiding this comment.
What was that actually? Are its values numeric or enum like?
| tileXTmp = this->DAT_SomeX; | ||
| if ((this->LogicLayer[this->DAT_SomeTile] & L_SEA) != 0) { | ||
| this->MiscDisplayLayer[this->DAT_SomeTile] | ||
| = this->MiscDisplayLayer[this->DAT_SomeTile] & 0xfffc; |
There was a problem hiding this comment.
0xfffc clears bits 0-1, which is MD_PILLAR_SIDESUnk. It is now & (ushort)~MD_PILLAR_SIDESUnk (6f13203). The cast stays because MiscDisplayLayer is declared short: without it, the constant becomes and eax, -4 instead of the original and eax, 0xfffc.
| } | ||
| shallowMaskMain = 0; | ||
| this->bitFlag = 0; | ||
| for (directionTmp = 0; directionTmp < 8; directionTmp++) { |
There was a problem hiding this comment.
Yes, it is the 8 directions. The loop is now < CD_UPPER_LIMIT, and so are the other bit and direction loops (pathBitValue, edgeBitId, moatDirectionValue). The field_0x370c scan uses countof(...) (6f13203).
| if ((this->LogicLayer[neighbourTilePos] | ||
| & (L_SEA | L_BORDER | L_BORDER_EDGE | L_RIVER)) | ||
| == 0) { | ||
| this->bitFlag |= 0x80 >> directionTmp; |
There was a problem hiding this comment.
Yes: 0x80 is NM_NORTH, and NM_NORTH >> d is the NeighbourMask bit for CardinalDirection d (N=0x80, NE=0x40, ... NW=1). It is now written that way at all six places (6f13203).
| if (this->bitFlag != 0) { | ||
| if ((this->bitFlag & NM_NORTH) != 0) { | ||
| if ((this->bitFlag & NM_EAST) != 0) { | ||
| bankDirection = 5; |
There was a problem hiding this comment.
Are these the enum directions, or something else?
There was a problem hiding this comment.
They are directions: the CardinalDirection the bank faces, away from the water (water N gives 4 = CD_SOUTH, water N+E gives 5 = CD_SOUTHWEST). They are rotated by mapOrientation in the same CD space. All assignments now use CD_* (6f13203).
| MACRO_NEIGHBOUR_FLAGS_GLOBAL_LOGIC_8(riv7, L_RIVER) | ||
| if (this->bitFlag != 0) { | ||
| tileHeightAt = this->HeightLayer[this->DAT_SomeTile]; | ||
| for (local_14_f = 0; local_14_f < 8; local_14_f++) { |
There was a problem hiding this comment.
It is the size of field_0x370c (8 directions), so it is now countof(DAT_TerrainDefinedData::instance.field_0x370c) (6f13203).
| this->GfxLayer[this->DAT_SomeTile] = GMFirstPictureIndex::instance[5] + 668 | ||
| + this->LuminesenceLayer[this->DAT_SomeTile] * 8 | ||
| + (this->RandomLayer[this->DAT_SomeTile] & 7); | ||
| for (local_14_f = 0; local_14_f < 7; local_14_f++) { |
There was a problem hiding this comment.
Yes, the same padded table: now countof(TerrainFlagGraphicLookup) - 1 with the comment (6f13203).
| this->GfxLayer[this->DAT_SomeTile] = 0; | ||
| continue; | ||
| } else { | ||
| goto plainTerrain; |
There was a problem hiding this comment.
Have you let the AI check the whole branches and conditions?
There are multiple gotos, but it could always be that certain checks are skippend, or and additional flag was used and/or (if not optimized maybe the only variant), that the scopes and branches are wrongly set and the cases can actually fall through to the cases.
There was a problem hiding this comment.
Yes. Beyond reading the code, it is checked by the match: updateGfxLayer is 100.0% raw in a full build with both resolver sets on (main merged, 6f13203). Every compare, branch target and shared tail is therefore identical to 0x509180, so no check is skipped and no case falls through differently. The flag-based and goto-free forms I tried are listed in the PR comment (best: 77.4%).
| SHC_3BB0A8C1_0x00508EC0 | 0.0% | Pending | ||
|
|
||
| SHC_3BB0A8C1_0x00509180 | 0.0% | Pending | ||
| SHC_3BB0A8C1_0x00509180 | 100.0% | Reimplemented |
There was a problem hiding this comment.
Added: the remark now says that the GMFirstPictureIndex entries are read through a volatile cast (GM_FIRST_PICTURE_INDEX) for the match (86d2783).
updateGfxLayer classifies a wall tile by the corner its two cardinal wall neighbours form: 1 = east+south, 2 = south+west, 3 = north+west, 4 = north+east, 0 = none. It then rotates that value by mapOrientation / 2 to pick the corner alpha graphic. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp
…d table sizes directionTranslationMatrix offsets use CardinalDirection (CD_*), with CD_UPPER_LIMIT for the row stride and the direction wrap. The shore switch cases are NeighbourMask combinations, NM_NORTH >> direction builds the neighbour bit, and bankDirection holds the CD direction the bank faces. The TerrainFlagGraphicLookup scans use countof - 1, because its last entry is zero padding. The listing is identical. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp
These two
Map::TileMapStatefunctions come from #396. They only match through tricks the review objects to, so they get their own PR, as #519 and #559 did for earlier functions.The tricks
getHeightAtTileIncludingOwnersBuildings(0x004FFF10): local noinline forwarder, 99.3% raw (100% normalized).return getTotalHeightAtTile(tile);. In the original they are two separate calls. The two targets are probably byte-identical functions that the linker folded into one address; only one resolver exists for 0x004FFB10..cpptherefore declares a__declspec(noinline)member forwarder in an anonymous namespace and calls it from the gatehouse arm. The code matches; reccmp reports only the forwarder's name at that call.updateGfxLayer(0x00509180):GMFirstPictureIndex::instance[9]read through avolatilecast in a local#define, 100% raw (95.2% normalized).#define GM_FIRST_PICTURE_INDEX(I) (*(int volatile*)&GMFirstPictureIndex::instance[I])covers the fivePillarGFXLayerstores.Trick-free forms tried
Each was measured with a full build and reccmp, both resolver sets on, every TileMapState source on main plus these two in the build:
getTotalHeightAtTilethrough the resolver directly&DAT_TileMapState::instance#define(this PR)GMFirstPictureIndex::instance[9]int const pillarPicturelocal per storeNo existing enum or constant on main stands in for index 9, and the only other resolver for 0x004FFB10 is the one the direct call already uses. A form without either trick would need a second, header-declared function for the folded twin of
getTotalHeightAtTile, which is a generated-header change.Review pass
Compared with #396:
updateGfxLayer, the other local macros are expanded inline:DIRECTION_OFFSET,SEA_EDGE_PICK,ROTATE_BITFLAG_BY_ORIENTATIONandMIN_OF(now Windows'min). Only the volatile#defineis left.getHeightAtTileIncludingOwnersBuildings, the== 0/!= 0tests are now truthiness checks.updateGfxLayer, the numbers are named: directions useCD_*/CD_UPPER_LIMIT, the shore switch cases useNM_*combinations, wall corners use the newWallCornerTypeenum (OpenSHC/Map/Enums/WallCornerType.hpp, the only header this PR adds), and the TerrainFlagGraphicLookup scans usecountof - 1.Two forms are kept because the readable one costs match:
this->directionTranslationMatrix[0][this->DAT_SomeY * CD_UPPER_LIMIT + d]keeps its flat form.[this->DAT_SomeY][d]changes the generated code: 93.4% raw / 49.0% normalized.local_14_fkeeps its name. The original's stack layout puts it in its declared slot only under this name. Each of the 20 other names tried (lookupIndex,i,fordIndex,flagIndex,local_14_g, …) moves it to the top of the frame in the compiler's listing and shifts three other locals. WithlookupIndexthe function drops from 100 to 98.8%.No
/GLor function-visibility entries are needed.🤖 Generated with Claude Code
https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp